<?php
namespace Admin\Controller;
use Tools\AdminController,    Model\UserModel,
    Model\News_contentsModel,    Model\SystemModel;

class IndexController extends AdminController {
    public function index(){
        $usmd = new UserModel();
        $stmd = new SystemModel();
        $ncmd = new News_contentsModel();
        
        //用户信息
        $admin_id   =  session('admin_id');
        $admin_name =  session('admin_name'); 
        $user       =  $usmd -> find($admin_id);
        $role_id    =  $user['user_role_id'];
        
        //角色
        $role     =  D('Role') -> find($role_id);
        $auth_ids =  $role['role_auth_ids'];
        
        //父级和子级权限
        $authA = D('Auth') -> where("auth_level=0 and auth_state!=0 and auth_id in($auth_ids)") -> select();
        $authB = D('Auth') -> where("auth_level=1 and auth_state!=0 and auth_id in($auth_ids)") -> select();

        //获得待审核的内容数量
        $dnumber = $ncmd -> where('state=0') -> count();
        //获得退稿的内容数量
        $tnumber = $ncmd -> where("state=2 AND author='{$admin_name}'") -> count();
        //将权限id字符串转换成数组
        $auths  = explode(',', $auth_ids);
        
        //取得系统基本信息       
        $web_name = $stmd -> where("system_name='web_name'") ->find();
        $web_logo = $stmd -> where("system_name='web_logo'") ->find();
        
        
        $this -> assign('auths',$auths);
        $this -> assign('authA',$authA);
        $this -> assign('authB',$authB);
        $this -> assign('tnumber',$tnumber);
        $this -> assign('dnumber',$dnumber);
        $this -> assign('web_name',$web_name);
        $this -> assign('web_logo',$web_logo);
        $this -> assign('admin_id',$admin_id);
        $this -> assign('admin_name',$admin_name);

        $this -> display();
    }
    
    
    function start(){
        //获得登陆者信息
        $usmd = new UserModel();
        $admin_id = session('admin_id');
        $user = $usmd -> find($admin_id);
        
        //服务器信息
        $system = array();
        $system['mysql'] = mysql_get_server_info();
        $system['apache'] = apache_get_version(); 
                
        $this -> assign('user',$user);        
        $this -> assign('system',$system);        
        $this -> display();
    }
    
    
    function find($type,$content){
        //判断查找的是哪个类型并跳转
        if($content){
            if($type==0){
                $this -> redirect('News/id_find',array('news_id'=>$content));
            }else if($type==1){
                $this -> redirect('News/contents_find',array('contents'=>$content));
            }else if($type==2){
                $this -> redirect('User/id_find',array('user_id'=>$content));
            }else if($type==3){
                $this -> redirect('User/name_find',array('user_name'=>$content));
            }
        }else {
            echo "请输入查询内容";
        }
    }
    
    
}